﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using Chowpoo.Sql;
using CourseSystem.Core.Entities;
using CourseSystem.Core.SqlServerDAL;

namespace CourseSystem.Core.BLL
{
    public class DepartmentBLL:CommonBLL<DepartmentInfo, DepartmentDAL>
    {

        public static IQueryable<DepartmentInfo> GetList(int id)
        {
            using (var dal = new DepartmentDAL(Settings.ConnectionName))
            {
                var re = dal.SelectQueryable(o => o.CollegeId == id);
                return re;
            }
        }

        public static List<DepartmentInfo> GetByColId(int id)
        {
            using (var dal = new DepartmentDAL(Settings.ConnectionName))
            {
                var re = dal.Select(o => o.CollegeId == id);
                return re;
            }
        }

        public static DepartmentInfo Get(int id)
        {
            using (var dal = new DepartmentDAL(Settings.ConnectionName))
            {
                var re = dal.SelectSingle(o => o.Id == id);
                return re;
            }
        }

        public static bool IsExist(Expression<Func<DepartmentInfo, bool>> expression)
        {
            using (var dal = new DepartmentDAL(Settings.ConnectionName))
            {
                return dal.SelectSingle(expression) != null;
            }
        }

        public static bool Del(int id)
        {
            using (var dal = new DepartmentDAL())
            {
                return dal.Delete(o => o.Id == id) != null;
            }
        }

    }
}
